package com.service.impl;

import com.POJO.StudentClass;
import com.mapper.StudentClassMapper;
import com.service.StudentClassService;
import com.util.MybatisConfig;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * StudentClassServiceImpl是StudentClassService的具体实现类，
 * 提供对学生班级信息的各种操作，如获取学生班级信息等。
 */
@Service
public class StudentClassServiceImpl implements StudentClassService {
    private StudentClassMapper studentClassMapper;
    private SqlSession sqlSession;

    // 初始化sqlSession和studentClassMapper
    private void openSession(){
        sqlSession = MybatisConfig.getSession();
        studentClassMapper = sqlSession.getMapper(StudentClassMapper.class);
    }

    /**
     * 根据学生ID获取学生的所有班级信息
     * @param studentId 学生ID
     * @return 学生班级信息列表
     */
    @Override
    public List<StudentClass> getStudentClassByStudentId(int studentId) {
        openSession();
        try {
            return studentClassMapper.getStudentClassesByStudentId(studentId);
        }catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            sqlSession.close();
        }
    }
}
